package com.vturkey.dao;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.vturkey.model.User;

@Repository("userDao") 
public class UserDao extends BasicDao {

	public boolean isAvailableUserName(String userName){
		
		boolean result=false;
		Session session = factory.openSession();
		try{
			Criteria criteria = session.createCriteria(User.class);
			criteria.createAlias("nameToken", "nToken");
			criteria.add(Restrictions.eq("nToken.userName",userName.trim()));
			criteria.setProjection(Projections.rowCount());
			result = ((Number)criteria.uniqueResult()).intValue()==0;
		}catch (Exception e) {
			
		}finally{
			session.close();
		}
		return result;
	}
	
	
	public Object get(Object id) {
		// TODO Auto-generated method stub
		return null;
	}

}